package com.tg.paw.common.util;

import com.alibaba.fastjson.JSON;
import com.tg.paw.common.generator.IdGeneratorUtil;
import com.tg.paw.common.model.MessageData;
import com.tg.paw.common.mq.entity.MqMessage;
import com.tg.paw.common.mq.entity.MqMessageLog;
import org.springframework.beans.BeanUtils;

import java.util.Date;

/**
 * @author Rubble
 * @date 2020/6/19
 */
public class MessageUtil {

    public static <T> String wrapMessage(T message){
        MessageData<T> messageData = new MessageData<>();
        // 可用uuid  IdUtil.randomUUID();
        String uid = IdGeneratorUtil.nextIdStr();
        messageData.setUuid(uid);
        messageData.setData(message);
        return JSON.toJSONString(messageData);
    }

    public static MqMessageLog buildMessageLog(MqMessage message) {
        MqMessageLog messageLog = new MqMessageLog();
        BeanUtils.copyProperties(message,messageLog);
        messageLog.setCreateTime(new Date());
        return messageLog;
    }
}
